#pragma once

#include <utility>
#include <vector>

namespace jianzhi_011
{

class Solution
{
public:
    int minArray(const std::vector<int>& nums)
    {
        int l = 0;
        int r = nums.size() - 1;
        while (l < r && nums.at(l + 1) == nums.at(l))
            ++l;
        while (r > l && nums.at(r - 1) == nums.at(r))
            --r;
        while (l < r) {
            int mid = (l + r + 1) / 2;
            if (nums.at(mid) < nums.at(mid - 1))
                return nums.at(mid);
            if (nums.at(mid) > nums.at(r))
                l = mid;
            else
                r = mid - 1;
        }
        return nums.at(l);
    }
};

}  /* namespace jianzhi_011 */
